sp = input().split()
strok = ''
for el in sp:
    if el == 'zero':
        strok += '0'
    elif el == 'one':
        strok += '1'
    elif el == 'two':
        strok += '2'
    elif el == 'three':
        strok += '3'
    elif el == 'four':
        strok += '4'
    elif el == 'five':
        strok += '5'
    elif el == 'six':
        strok += '6'
    elif el == 'seven':
        strok += '7'
    elif el == 'eight':
        strok += '8'
    elif el == 'nine':
        strok += '9'
    else:
        print('Wrong input')
        break
if len(strok) == 3:
    n = int(strok)
    number = 0
    l = True
    while l:
        nmin, nmax = n - number, n + number
        for i in range(2, nmin // 2 + nmin % 2 + 1):
            if nmin % i == 0:
                break
            if i == nmin // 2 + nmin % 2:
                print(nmin)
                l = False
        for i in range(2, nmax // 2 + nmax % 2 + 1):
            if nmax % i == 0:
                break
            if i == nmax // 2 + nmax % 2:
                if l:
                    print(nmax)
                    l = False
        number += 1